package info.jbohn.view;

import info.jbohn.data.Feed;
import info.jbohn.model.RSSMainModel;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionListener;

public class RSSLeftUI extends JPanel implements ViewInterface{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel lblNewLabel;
	private JList<String> list;
	public RSSLeftUI() {
		setLayout(new BorderLayout(0, 0));
		
		lblNewLabel = new JLabel("New label");
		add(lblNewLabel, BorderLayout.NORTH);
		
		list = new JList<String>();
		add(list, BorderLayout.CENTER);
	}
	@Override
	public void displayUI() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void updateUI(RSSMainModel model) {
		List<Feed> feeds = model.getFeeds();
		DefaultListModel<String> listmodel = new DefaultListModel<String>();
		
		for (Feed feed : feeds) {
			listmodel.addElement(feed.getTitle());
		}
		
		list.setModel(listmodel);
	}
	@Override
	public <T> void register(T list) {
		this.list.addListSelectionListener((ListSelectionListener)list);
	}

}
